// index.js
import { REQUEST_BANNER, REQUEST_RECOMMENDLIST, REQUEST_TOPLIST } from '../../api/index.js'
Page({
  data: {
    bannerList: [],
    recommendList: [],
    topList: []
  },
  async onLoad() {
    const { banners } = await REQUEST_BANNER({ type: 2 });
    const { result } = await REQUEST_RECOMMENDLIST({limit: 10 });
    let index = 0;
    const resultArr = [];
    while(index < 5) {
      const { playlist } = await REQUEST_TOPLIST({idx: index ++ });
      const topListItem = { name: playlist.name, tracks: playlist.tracks.slice(0, 3) };
      resultArr.push(topListItem);
      this.setData({ topList: resultArr });
    };

    this.setData({ bannerList: banners, recommendList: result });
    
  },
  toRecommendSong() {
    wx.navigateTo({ url: '/pages/recommendSong/recommendSong' });
  },
  toSearch() {
    wx.navigateTo({url: '/pages/search/search'});
  },
});